package com.luych.toolbox.base.service.dao;

import com.luych.toolbox.base.service.entity.Task;
import com.luych.toolbox.common.enums.TaskStatus;
import com.luych.toolbox.common.enums.TaskType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface TaskDao extends JpaRepository<Task, String>, JpaSpecificationExecutor<Task> {

    Page<Task> findByStatus(TaskStatus status, Pageable pageable);

    @Query("SELECT AVG(cost) AS evaluate FROM Task WHERE type = :type")
    Long avgCostByType(TaskType type);

}